﻿using _5E.Infrastructure.Logging;
using _5E.Infrastructure.UnitOfWork;
using _5E.NHibernateRepository;
using StructureMap;
using WholesaleOnline.Contract;
using WholesaleOnline.Controller.Handlers;
using WholesaleOnline.Controller.Request;
using WholesaleOnline.Controller.Storage;
using WholesaleOnline.Infrastructure.Configuration;
using WholesaleOnline.Infrastructure.Logging;
using WholesaleOnline.Model.Repository;
using WholesaleOnline.Repository;
using WholesaleOnline.Service.Services;

namespace WholesaleOnline.Controller
{
    public class StructureMapBootstrapper
    {
        public static void Bootstrap()
        {
            ObjectFactory.Configure(x =>
            {
                x.For<IAccountService>().Use<AccountService>();
                x.For<IBasketService>().Use<BasketService>();
                x.For<IBuyerHomePageService>().Use<BuyerHomePageService>();
                x.For<IInventoryService>().Use<InventoryService>();

                x.For<IAccountRepository>().Use<AccountRepository>();
                x.For<IAttributeRepository>().Use<AttributeRepository>();
                x.For<IBasketItemRepository>().Use<BasketItemRepository>();
                x.For<IBasketRepository>().Use<BasketRepository>();
                x.For<IBuyerProductRepository>().Use<BuyerProductRepository>();
                x.For<IBuyerRepository>().Use<BuyerRepository>();
                x.For<IKeywordRepository>().Use<KeywordRepository>();
                x.For<IProductRepository>().Use<ProductReopsitory>();
                x.For<ISellerRepository>().Use<SellerRepository>();
                x.For<ISellerAttributeRepository>().Use<SellerAttributeRepository>();

                x.For<IHandlerFactory>().Use<HandlerFactory>();
                x.For<IHttpStorage>().Use<HttpStorage>();
                x.For<ILogger>().Use<Log4NetAdapter>();
                x.For<IMyApplicationSettings>().Use<WebConfigApplicationSettings>();
                x.For<IUnitOfWork>().Use<NHibernateUnitOfWork>();
                x.For<IWebRequestFactory>().Use<WebRequestFactory>();
            });

            MyApplicationSettingsFactory.InitializeApplicationSettingsFactory(ObjectFactory.GetInstance<IMyApplicationSettings>());
            LoggingFactory.InitializeLogFactory(ObjectFactory.GetInstance<ILogger>());
        }
    }
}
